<?php
namespace App\Controllers;

use App\Library\App;
use App\Models\SysUser;

class SignController extends BaseController {

    public function initialize() {
        parent::initialize();
    }

    //-------------------------------------------------------------------------
    // 首页
    //-------------------------------------------------------------------------
    public function indexAction() {
    }

    //-------------------------------------------------------------------------
    // 登录
    //-------------------------------------------------------------------------
    public function inAction() {
        if($this->request->isGet()) {
            $this->display('/sign/in');
        } else {
            $data = [
                'account'  => $this->request->getPost('account'),
                'password' => $this->request->getPost('password')
            ];
            if($data['account'] == '') {
                return $this->sendAjax(false, "登录失败，账户名称不能为空！");
            }
            if($data['password'] == '') {
                return $this->sendAjax(false, "登录失败，账户密码不能为空！");
            }

            $user = new SysUser();
            $ret  = $user->getByAccount($data['account']);
            if($ret === false) {
                return $this->sendAjax(false, "登录失败，没有找到此账户！");
            }
            if($ret['password'] != md5($data['password'])) {
                return $this->sendAjax(false, "登录失败，密码错误！");
            }

            App::setCurrentUserUid($ret['id']);
            return $this->sendAjax(true, []);
        }
    }

    //-------------------------------------------------------------------------
    // 登出
    //-------------------------------------------------------------------------
    public function outAction() {
    }
}